<?php
$pageTitle = "教师参加的培训列表";
include 'header.php';

// 检查是否传递了 teacher_id
if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("未指定教师");
}

$teacher_id = intval($_GET['id']); // 转换为整数防止 SQL 注入

// 查询教师参加过的培训 - 请根据你的实际表结构调整
$sql = "SELECT 
            t.id,
            t.title,
            t.start_time,
            t.end_time,
            t.location,
            t.department,
            t.type,
            tt.teacher_name
        FROM trainings t
        INNER JOIN trainings_teachers tt ON t.id = tt.training_id
        WHERE tt.teacher_id = ?
        ORDER BY t.start_time DESC";

// 使用预处理语句防止SQL注入
$stmt = $pdo->prepare($sql);
$stmt->execute([$teacher_id]);

// 存储查询结果
$trainings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $trainings[] = $row;
}
?>

<h1>教师参加的培训列表</h1>

<?php if (count($trainings) > 0): ?>
    <div class="table-responsive">
        <table class="table table-striped table-hover table-bordered">
            <thead>
                <tr>
                    <th>#</th>
                    <th>教师</th>
                    <th>主题</th>
                    <th>时间</th>
                    <th>地点</th>
                    <th>主办科室或学校</th>
                    <th>任务或自主</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($trainings as $training): ?>
                    <tr>
                        <td><?= htmlspecialchars($training['id']) ?></td>
                        <td><?= htmlspecialchars($training['teacher_name']) ?></td>
                        <td><?= htmlspecialchars($training['title']) ?></td>
                        <td><?= htmlspecialchars($training['start_time'] . ' 至 ' . $training['end_time']) ?></td>
                        <td><?= htmlspecialchars($training['location']) ?></td>
                        <td><?= htmlspecialchars($training['department']) ?></td>
                        <td><?= htmlspecialchars($training['type']) ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
<?php else: ?>
    <div class="no-trainings">该教师尚未参加任何培训</div>
<?php endif; ?>
<?php include 'footer.php'; ?>